package com.atguigu.guli.service.vod.controller;

import com.atguigu.guli.service.base.result.R;
import com.atguigu.guli.service.vod.service.MediaService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@Api(tags = "视频管理")
@RestController
@CrossOrigin
@RequestMapping("/admin/vod/media")
public class AdminMediaController {

    @Autowired
    private MediaService mediaService;

    // 上传视频
    @PostMapping("upload")
    public R upload(MultipartFile file) {
        String vId = mediaService.upload(file);
        return R.ok().data("id", vId);
    }

    // 获取未加密视频播放地址
    @GetMapping("getPlay/{vId}")
    public R getPlay(@PathVariable String vId) {
        String playUrl = mediaService.getPlay(vId);
        return R.ok().data("playUrl", playUrl);
    }

    //获取加密视频播放凭证
    @GetMapping("playAuth/{vId}")
    public R getPlayAuth(@PathVariable String vId) {
        String playAuth = mediaService.getPlayAuth(vId);
        return R.ok().data("playAuth", playAuth);

    }

}
